package com.example.demo.Controller;

import com.example.demo.Dao.RiderDao;
import com.example.demo.Entity.CustomerEntity;
import com.example.demo.Entity.ResultEntity;
import com.example.demo.Entity.RiderEntity;
import com.example.demo.Service.RiderService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/api/rider")
@CrossOrigin
public class RiderController {
    @Resource
    RiderService riderService;

    @RequestMapping(value = "/getRiderInfo")
    public ResultEntity GetRider() {
        List<RiderEntity> riderEntities;
        riderEntities = riderService.get();

        ResultEntity res = new ResultEntity();
        res.setCode(20000);
        res.setData(riderEntities);
        return res;
    }

    @RequestMapping(value = "/getRiderInfoByAccounts")
    public ResultEntity GetCustomerInfoByAccounts(@RequestParam("accounts") String accounts) {
        RiderEntity riderEntities;
        riderEntities = riderService.getByAccounts(accounts);

        ResultEntity res = new ResultEntity();
        res.setCode(20000);
        res.setData(riderEntities);
        return res;
    }

    @RequestMapping(value = "/updateRiderInfoByAccounts")
    public ResultEntity UpdateCustomerInfoByAccounts(@RequestBody RiderEntity data) {
        int riderEntities;
        riderEntities = riderService.updateByAccounts(data.getAccounts(),data.getUsername(),data.getPassword(),data.getTelephone(),data.getLicense(),data.getAvatar(),data.getGender(),data.getStatus());

        ResultEntity res = new ResultEntity();
        res.setCode(20000);
        res.setData(riderEntities);
        return res;
    }

    @RequestMapping(value = "/addRider")
    public ResultEntity AddRider(@RequestBody RiderEntity data) {
        int riderEntities;
        riderEntities = riderService.addRider(data.getAccounts(),data.getUsername(),data.getPassword(),data.getTelephone(),data.getLicense(),data.getAvatar(),data.getGender());

        ResultEntity res = new ResultEntity();
        res.setCode(20000);
        res.setData(riderEntities);
        return res;
    }

    @RequestMapping(value = "/deleteRider")
    public ResultEntity DeleteCustomer(@RequestParam("accounts") String accounts) {
        int riderEntities;
        riderEntities = riderService.deleteRider(accounts);

        ResultEntity res = new ResultEntity();
        res.setCode(20000);
        res.setData(riderEntities);
        return res;
    }
}
